﻿Namespace Core

    ''' <summary>
    ''' Internal class for download websites
    ''' </summary>
    ''' <remarks></remarks>
    Friend NotInheritable Class HttpConnector
        Implements IHTTPConnector

        ''' <summary>
        ''' Download the content from the given url
        ''' </summary>
        ''' <param name="url">valid url!</param>
        ''' <returns>content or empty string after exception</returns>
        ''' <remarks></remarks>
        Public Function GetWebserviceResponse(ByVal url As String) As String Implements IHTTPConnector.GetWebserviceResponse
            Dim ioWebResponse As System.IO.Stream = Nothing
            Dim webResponseReader As System.IO.StreamReader = Nothing
            Dim webrequest As System.Net.WebRequest
            Dim retVal As String = Nothing
            Try
                webrequest = System.Net.WebRequest.Create(url)
                ioWebResponse = webrequest.GetResponse.GetResponseStream
                webResponseReader = New System.IO.StreamReader(ioWebResponse)
                retVal = webResponseReader.ReadToEnd
            Catch ex As NotSupportedException
            Catch ex As OutOfMemoryException
            Catch ex As IO.IOException
                retVal = String.Empty
            Finally
                webrequest = Nothing
                If webResponseReader IsNot Nothing Then
                    webResponseReader.Close()
                    webResponseReader.Dispose()
                    webResponseReader = Nothing
                End If
                If ioWebResponse IsNot Nothing Then
                    ioWebResponse.Close()
                    ioWebResponse.Dispose()
                    ioWebResponse = Nothing
                End If
            End Try
            Return retVal
        End Function

    End Class

End Namespace
